<?php
class Block_ShowMenu extends Zend_View_Helper_Abstract{
    public function ShowMenu($lang){
        $catModel = new Default_Model_DbTable_Category();
        $allCat = $catModel->getCatByLang($lang);
        /* $menus = $this->SubMenu(0, $allCat->toArray());
        echo $menus; */
        //echo $this->data2xml($allCat->toArray(),0,'','-','./cat','.html');
        $data = array();
        $cats = $allCat->toArray();
        foreach ($cats as $c){
        	$data[$c["parent"]][] = $c;
        }
        echo $this->MenuUl($data, 0,'','-','./cat','/html');
    }
    
    function MenuUl($data,$parent = 0,$parents = '',$sep = '/',$dir,$ext = ''){
    	$str = '';
    	if(isset($data[$parent])){
    		$str .= '<ul class="nav">';
    		if($parents) $parents .= $sep.$parent;
    		else $parents = $dir;
    		foreach($data[$parent] as $rs){
    			$str .= '<li><a href="'.$parents.$sep.$rs['cat_id'].$ext.'">'.$rs['lang'].'</a></li>';
    			$str .= $this->MenuUl($data,$rs['cat_id'],$parents,$sep,$dir,$ext);
    		}
    		$str .= '</ul>';
    	}
    	return $str;
    }
    
    function SubMenu($parentID,$aCats,$res = "",$sep=""){
    	foreach ($aCats as $v){
    		if($v["parent"] == $parentID){
    			$re = $sep."<a href=".DOMAIN."/".$v["cat_name"]."/".$v["cat_id"].">".$v["lang"]."</a><br/>";
    			$res.=$this->SubMenu($v["cat_id"],$aCats,$re,$sep."--");
    		}
    	}
    	return $res;
    }
}